package com.work.straighttalk.presenter;

import com.work.straighttalk.bean.User;
import com.work.straighttalk.model.SearchUserMImpl;
import com.work.straighttalk.model.i.OnSearchUserListener;
import com.work.straighttalk.model.i.SearchUserMI;
import com.work.straighttalk.presenter.i.SearchUserPI;
import com.work.straighttalk.ui.i.SearchUserVI;

import java.util.List;

/**
 * Created by dllo on 16/3/4.
 */
public class SearchUserPImpl implements SearchUserPI, OnSearchUserListener {
    private SearchUserVI searchUserVI;
    private SearchUserMI searchUserMI;

    public SearchUserPImpl(SearchUserVI searchUserVI) {
        this.searchUserVI = searchUserVI;
        this.searchUserMI = new SearchUserMImpl();
    }

    @Override
    public void onUserNull() {
        if (searchUserVI != null) {
            searchUserVI.userNUll();
        }
    }

    @Override
    public void onSearchUserError(int i, String s) {
        if (searchUserVI != null) {
            searchUserVI.UserError(i, s);
        }
    }

    /**
     * OnSearchUserListener的回调
     *
     * @param list
     */
    @Override
    public void setList(List<User> list) {
        if (searchUserVI != null) {
            searchUserVI.showItem(list);
        }

    }

    @Override
    public void validateUserGetList(String username) {
        searchUserMI.verification(username, this);
    }

    @Override
    public void onDestroy() {
        searchUserVI = null;
    }
}
